<?php

//关闭事物自动提交
$db->mysqlDB->falseAutoCommit();

//获取请求必传参
$requestParams = $route->bodyParams['bad_request_params'];

//删除请求参数中的请求必传参
unset($route->bodyParams['bad_request_params']);


//保存新增成功后的ID
$R1 = $db->mysqlDB->automaticAdd($route->bodyParams)->insert("sys_bussiness_api_docs");

//判断是否需要增加请求参数信息
if(count($requestParams) <= 0){

    $db->mysqlDB->actionCommint();
    $db->mysqlDB->trueAutoCommit();
    $response->responseData(true);

}

//拼接多新增语句SQL
$addRequestSql = "INSERT INTO sys_bussiness_api_docs_request_parameter";

$keys = "(badrp_badid,badrp_name,badrp_is_must,badrp_rule,badrp_type,badrp_note,badrp_way) VALUES";

$values = "";

for($i=0;$i<count($requestParams);$i++){

    $paramsName   = trim($requestParams[$i]['badrp_name']);
    $paramsRule   = trim($requestParams[$i]['badrp_rule']);
    $paramsIsMust = trim($requestParams[$i]['badrp_is_must']);
    $paramsType   = trim($requestParams[$i]['badrp_type']);
    $paramsNote   = trim($requestParams[$i]['badrp_note']);
    $paramsWay    = trim($requestParams[$i]['badrp_way']);

    $tmpValue = "(";
    $tmpValue .= $R1 . ",'" . $paramsName . "',".$paramsIsMust.",'" . $paramsRule . "','" . $paramsType . "','" . $paramsNote . "','" . $paramsWay . "'";
    $tmpValue .= "),";

    $values .= $tmpValue . "";

}

//拼接最终SQL
$addRequestSql .= $keys .= rtrim($values, ",");

//执行SQL
$R2 = $db->mysqlDB->queryTransaction($addRequestSql);

//判断两个操作是否执行成功
if (!$R1 || !$R2) {
    $db->mysqlDB->rollBackCommint();
    $response->responseData(false);
}else{
    $db->mysqlDB->actionCommint();
    $db->mysqlDB->trueAutoCommit();
}

$response->responseData(true);